

rem
bbdoc: Fixed time step and render tweening.
end rem
Type TFixedTime

	Field _accumulator:Double
	Field _deltaTime:Double
	Field _time:Double

	
	Method New()
		SetUpdateFrequency(60)
	End Method
	
	
	Rem
	bbdoc: Sets the frame rate.
	about: The frame rate is converted to millisecs.
	endrem	
	Method SetUpdateFrequency(f:Int)
		_deltaTime = 1000.0:Double / f
	End Method
	
	
	Rem
	bbdoc: Calculates and returns the render tweening value used to smooth out frames.
	returns: Double
	endrem	
	Method GetTweening:Double()
		Return _accumulator / _deltaTime		
	End Method
	
		
	Rem
	bbdoc: Returns update delta time (in millisecs)
	returns: Double
	endrem
	Method GetDeltaTime:Int()
		Return _deltaTime
	End Method
	
	
	Rem
	bbdoc: Resets the timer.
	endrem
	Method Reset()
		_time = MilliSecs()
		_accumulator = 0		
	End Method
	
	
	Rem
	bbdoc: Adds passed time to the accumulator.
	about: This is called from the TGame2D.Run() method.
	endrem
	Method Update:Int()
		Local thistime:Double = MilliSecs()
		Local passedtime:Double = thistime - _time
		
		_time = thistime
		_accumulator:+ passedtime
	End Method
	
	
	Rem
	bbdoc: Returns true if a logic step is needed.
	about: This is called from the TGame2D.Run() method.
	returns: True if an update is needed.
	endrem	
	Method TimeStepNeeded:Int()
		If _accumulator >= _deltaTime
			_accumulator:- _deltaTime
			Return True
		End If
		Return False
	End Method	
	
End Type
